﻿#region Copyright

//  ======================================================
//      Copyright (c) 2011 Toulr All rights reserved.
//     
//      The use and distribution terms for this software are contained in the file
//      named license.txt, which can be found in the root of this distribution.
//      By using this software in any fashion, you are agreeing to be bound by the
//      terms of this license.
//     
//     You must not remove this notice, or any other, from this software.
//  ======================================================

#endregion

#region Using Namespaces

using System;
using System.Globalization;
using System.Resources;
using Toulr.Resources;

#endregion

namespace Toulr.Models
{
    /// <summary>
    ///   所有模型定义用的基础模型，包括好多
    /// </summary>
    public class BaseModel
    {
        protected static ResourceManager ViewResourceManager = View.ResourceManager;

        public BaseModel()
        {
            if (CurrentCultureInfo == null) CurrentCultureInfo = DefaultCultureInfo;
        }

        public BaseModel(string modelName)
        {
            ModelName = modelName;
            if (CurrentCultureInfo == null) CurrentCultureInfo = DefaultCultureInfo;
        }

        protected String ModelName { get; set; }

        public static CultureInfo DefaultCultureInfo
        {
            get { return new CultureInfo("zh-CN", false); }
        }

        public CultureInfo CurrentCultureInfo { get; set; }

        /// <summary>
        ///   获取资源字符
        /// </summary>
        public String GetString(String keyName)
        {
            if (keyName.StartsWith("_"))
                keyName = ModelName + keyName;
            return ViewResourceManager.GetString(keyName, CurrentCultureInfo);
        }
    }
}